<?php
include('include/config.php');
?>
<!DOCTYPE html>
<html lang="ro">
  <head>
    <meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=10; IE=9; IE=8; IE=7; IE=EDGE" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="Palangeanu Lucian, 0727 448 535">
	<title><?php echo $_['logo']; ?></title>
	<link href="css/start/jquery-ui-1.10.4.custom.css" rel="stylesheet">

	<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
	<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
	<link href="css/style.css" rel="stylesheet">
<head>
<body >
		<div id="black">
			<div id="loading">
				<div id="infoBlack" ><br/></div>
				<img src="img/ajaxLoading.gif"><br/><br/>
				 <button onclick="location.reload();" type="button" class="btn btn-primary">Ok</button>
			</div>
		</div>
	<div class="container">
		<div id="header">
			<div id="logo">
				<img src="img/logo.png" width="220" />
				<h1 style="font-size:9px;margin:0;padding-top:4px;"><?php echo $_['logo']; ?></h1>
			</div>
			<div id="limba">
				<div class="steag" id="ro"><img src="img/ro.gif"></div>
				<div class="steag" id="en"><img src="img/en.gif"></div>
			</div>
		</div>
		<div class="jumbotron">
			<div class="row">
				  <div class="col-md-4 left">
						<ul id="tabNav" class="nav nav-tabs">
						  <li class="active"><a href="#evenimente" data-toggle="tab"><?php echo $_['evenimente']; ?></a></li>
							<li><a href="#statii" id="statiis" data-toggle="tab"><?php echo $_['stations']; ?></a></li>
						  <li><a href="#resquest" data-toggle="tab"><?php echo $_['resquest']; ?></a></li>
							<li><a href="#download" data-toggle="tab"><span class="glyphicon glyphicon-download-alt"></span></a></li>
						  <!--
						  <li class="dropdown">
							<a class="dropdown-toggle" data-toggle="dropdown" href="#">Test <span class="caret"></span></a>
							<ul class="dropdown-menu">
									  <li><a href="#resquest" data-toggle="tab">Resquest</a></li>
							</ul>
						 </li>
						 -->
						</ul>
						<div class="tab-content">
						
							<!-- EVENIMENTE -->
							<div class="tab-pane active" id="evenimente">
								<h3><?php echo $_['titlu_tab_evenimente']; ?></h3>

								<div class="form-group">
									<label><?php echo $_['label_data']; ?></label>
										<div class="clearfix"></div>
									<div class="col-xs-6">
										<label><?php echo $_['label_din_data']; ?></label>
										<input type="text" id="de_la_data" class="form-control dataeveniment"  placeholder="<?php echo date("Y-m-d",time()-3600*24); ?>">
									  </div>
									  <div class="col-xs-6">
										<label><?php echo $_['label_pana_la_data']; ?></label>
										<input type="text" id="pana_la_data"class="form-control dataeveniment" placeholder="<?php echo date("Y-m-d"); ?>">
									  </div>
								</div>
								
								
								<br /><br /><br />
								<div class="form-group">
									   <label><?php echo $_['label_mag']; ?> <small>(mai mare de:)</small></label>
										<input type="text" id="magnitudine" class="form-control"  placeholder="3"><br />
										<div id="sliderMagnitudine"></div>
								</div>
								<div class="form-group">
										<label><?php echo $_['label_adancime']; ?></label>
										<div class="clearfix"></div>
										<div class="col-xs-6">
											<input type="text" id="adancimeDeLa" class="form-control"  placeholder="45">
										</div>
										<div class="col-xs-6">
											<input type="text" id="adancimePanaLa" class="form-control"  placeholder="150">
										</div>
										<br /><br /><br />
										<div id="sliderAdancime"></div>
								</div>
								<div class="form-group">
									<label><?php echo $_['label_coordonate']; ?></label>
									<div class="coordonate">
										<div id="nord_case">
											<label><?php echo $_['label_nord']; ?></label>
											<input type="text" id="nord" class="form-control" style="width:60px"  placeholder="90">
										</div>
										<div id="vest_case">
											<label style="margin-top:5px;"><?php echo $_['label_vest']; ?></label>
											<input type="text" id="vest" class="form-control" style="width:60px;" placeholder="-180">
										</div>
										<div id="est_case">
											<label style="margin-top:5px;"><?php echo $_['label_est']; ?></label>
											<input type="text" id="est" class="form-control" style="width:60px;" placeholder="180">
										</div>
										<div id="sud_case">
											<input type="text" id="sud" class="form-control" style="width:60px" placeholder="-90">
											<label><?php echo $_['label_sud']; ?></label>
										</div>
									</div>
								</div>
								  <button onclick="location.reload();" type="button" class="btn btn-primary"><?php echo $_['buton_reseteaza']; ?></button>
								  <button type="button" id="cauta_eveniment" class="btn btn-primary" style="float:right">Cauta</button>
								<div class="clearfix"></div>
							</div>
							<!-- EVENIMENTE -->
							
							
							<!-- STATII -->
							<div class="tab-pane" id="statii">

									<div class="form-group">
										<div id="tabs">
											Cauta statii dupa:
											<ul>
												<li><a href="#tabs-1" id="cod">Cod</a></li>
												<li><a href="#tabs-2" id="regiune">Regiune</a></li>
												<li><a href="#tabs-3" id="eveniment">Evenimente</a></li>
											</ul>
											<div id="tabs-1">
												<select class="form-control" id="statiiByCod">
													<option value="0">Loading...</option>
												</select>
											</div>
											<div id="tabs-2">
												momentan indisponibil
												<?php /*
												<div class="coordonate" style="margin-left:-20px;">
													<div id="nord_case">
														<label><?php echo $_['label_nord']; ?></label>
														<input type="text" id="nord" class="form-control" style="width:60px"  placeholder="90">
													</div>
													<div id="vest_case">
														<label style="margin-top:5px;"><?php echo $_['label_vest']; ?></label>
														<input type="text" id="vest" class="form-control" style="width:65px;" placeholder="-180">
													</div>
													<div id="est_case">
														<label style="margin-top:5px;"><?php echo $_['label_est']; ?></label>
														<input type="text" id="est" class="form-control" style="width:65px;margin-left:-5px;" placeholder="180">
													</div>
													<div id="sud_case">
														<input type="text" id="sud" class="form-control" style="width:60px" placeholder="-90">
														<label><?php echo $_['label_sud']; ?></label>
													</div>
												</div>
												*/?>
											</div>
											<div id="tabs-3">
											<div style="max-height:300px;width:270px;overflow-y:scroll;">
												<form>
												<table class="table">
													<thead>
													<tr>
														<th><input type="checkbox" id="select_all"/></th>
														<th>Id Eveniment</th>
														<th>Tara</th>
														<th>Statie</th>
													</tr>
													</thead>
													<tbody id="statiidupaeveniment">
														
													</tbody>
												</table>
												</form>
											</div>
												<!--
												<b>Filter by</b>
												<div id="eventdist" style="margin-bottom:5px;">
													<label style="font-weight:normal;font-size:12px;">Event Distance (<font id="fromdist">0</font> to <font id="fromdist2">180</font> degrees)</label>
													<div id="Event_Distance"></div>
												</div>
												<div id="eventazmuth">
													<label style="font-weight:normal;font-size:12px;">Event Distance (<font id="fromazmuth">0</font> to <font id="fromazmuth2">180</font> degrees)</label>
													<div id="Event_Azimuth"></div>
												</div>
												-->
												
											</div>
										</div>
									</div>
									
									<div class="form-group">
										<label>Stream</label><br/>
										<i style="color:#e6e6e6;cursor:no-drop" title="Optiune momentan indisponibila">Choose the desired set of channels: Use SHIFT and CTRL to extend the set.</i>
									<fieldset disabled title="Optiune momentan indisponibila">
										<select multiple="multiple" class="form-control senzoriSelect" name="senzorilista" id="disabledSelect" >

										</select>
										</fieldset>
									</div>
									  <button onclick="location.reload();" type="button" class="btn btn-primary"><?php echo $_['buton_reseteaza']; ?></button>
								  <button type="button" id="cauta_statii" class="btn btn-primary" style="float:right" onclick="cod()"><?php echo $_['buton_cauta']; ?></button>
								<div class="clearfix"></div>
							</div>
							<!-- STATII -->
							
							
							
							<!-- RESQUEST -->
							<div class="tab-pane" id="resquest">
							<label>Selecteaza totate staiile:</label>
								<div class="col-xs-10">
									<input type='radio' name='allstation'  value='da'  />
													Yes
									<input type='radio' name='allstation' value='nu'  checked  />
													No
								</div>
								<div class="clearfix"></div>
								<br />
								<label>Time Window selection:</label>
								<div id="tabs_resq">
											<ul>
												<li><a href="#tabs_resq-1" id="relative">Relative Mode</a></li>
												<li><a  href="#tabs_resq-2" id="absolute">Absolute Mode</a></li>
											</ul>
											<div id="tabs_resq-1">
												<div class="col-xs-12">
													Start <small>(minutes before)</small><br />
													<input style="font-size:12px" min="0" type="text" name="minutebefore" id="minutebefore" class="form-control"  value="-5" >
													<div id="sliderstartbefore"></div>
												</div>
												<div class="col-xs-12">
													End <small>(minutes after)</small><br />
													<input style="font-size:12px" type="text" id="minuteafter" name="minuteafter" class="form-control" value="5" >
													<div id="sliderstartend"></div>
												</div>
											</div>
											<div id="tabs_resq-2">
												<div class="col-xs-12">
													Start:<br />
													<input style="font-size:12px" type="text" id="startdatetrim" class="form-control datetimepick " placeholder="<?php echo date("Y-m-d"); ?>">
												</div>
												<div class="col-xs-12">
													End:<br />
													<input style="font-size:12px" type="text" id="enddatetrim" class="form-control datetimepick" placeholder="<?php echo date("Y-m-d"); ?>">
												</div>
											</div>
											<div class="clearfix"></div>
											<br />
										</div>	
											
											
										<div style="clear:both"></div>
										
											<div style="margin-top:40px;height:100px;">
												<label>Request Information:</label>
												<br />
												Request type: 
												<div class="col-xs-10">
													<input type='radio' name='tipResquest' value='MSEED' checked  />
													Waveform (Mini-SEED)
												</div>
												<div class="col-xs-10">
													<fieldset disabled title="Optiune momentan indisponibila">
													<input type='radio' name='tipResquest' value='INVENTORY'  />
													Metadata (Inventory XML)
													</fieldset>
												</div>
											</div>
											<div class="clearfix"></div>
											
											
											<div style="margin-top:40px;height:100px;">
												<label>Type Fetch:</label>
												<br />
												<div class="col-xs-10">
													<input type='radio' name='tipfetch' value='scart' checked  />
													SCART
												</div>
												<div class="col-xs-10">
													<input type='radio' name='tipfetch' value='arclink'  />
													ARCLINK
												</div>
											</div>
											<div class="clearfix"></div>
										
											<div style="margin-top:30px;height:100px;">
													<label>Email</label><br/>
												<div class="col-xs-10">
													Your e-mail adress:
													<input type='text' name='email'  />
												</div>
											</div>
											 <button type="button" id="aplicaFiltru" onclick="absolute()" class="btn btn-primary" style="float:right;" onclick="">Submit</button>
											<div class="clearfix"></div>
								
							</div>
							<!-- RESQUEST -->
							
							
							<!-- DOWNLOAD -->
							<div class="tab-pane" id="download">
								<label>Verifica daca exista vre un resquest </label>
								
								<div class="col-xs-10">
									Your e-mail adress:
									<input type='text' name='email_vf' id="email_vf" />
								</div>
								<button type="button" id="verifica_request" class="btn btn-primary" style="float:right;" >Verifica</button>
									<div class="clearfix"></div>
							</div>
							<!-- DOWNLOAD -->
							
							
							
							
							
							
						</div>
				  </div>
				  <div class="col-md-8 right">
					<div class="panel panel-default">
					  <div class="panel-heading"><?php echo $_['titlu_tab_harta']; ?></div>
					  <div class="panel-body">
						<div id="mapEvent" style="height:300px"></div>
						<small>
							Use left SHIFT + drag mouse to select regions.
						</small>
					  </div>
					</div>
					<div class="panel panel-default">
					  <div class="panel-heading"><?php echo $_['titlu_tab_lista']; ?></div>
					  <div class="panel-body" id="lista_evenimente">
							<button type="button" id="cauta_statii_eveniment" class="btn btn-primary" style="position:relative;margin-right:10px;margin-bottom:10px;" onclick="">Statiile evenimentelor</button>
							<div id="mapEvent" >
							
							<div id="eveLista" >
								<b> Evenmimente: (<font  id="nr_evenimente"></font>)</b>
								<table class="table table-striped table-bordered" cellspacing="0" width="100%" id="evebimenteTB" >
									<thead >
									<tr>
										<th></th>
										<th style="width:200px;"><?php echo $_['tabel_timp']; ?></th>
										<th><?php echo $_['tabel_mag']; ?></th>
										<th><?php echo $_['tabel_adancime']; ?></th>
										<th><?php echo $_['tabel_lng']; ?></th>
										<th><?php echo $_['tabel_lat']; ?></th>
										<th><?php echo $_['tabel_regiune']; ?></th>
									</tr>
									</thead>
									<tbody id="tbodyLista" ></tbody>
								</table>

							</div>
							<div class="clearfix"></div>
							<br/>
							<div id="listaStatiibyEvents">
								<div id="boxinfoEveniment" style="height:210px;overflow-x:hidden;">
									<table class="table">
											<thead>
											<tr>
												<th>#</th>
												<th><?php echo $_['tabel_network']; ?></th>
												<th><?php echo $_['tabel_station']; ?></th>
												<th><?php echo $_['tabel_lat']; ?></th>
												<th><?php echo $_['tabel_lng']; ?></th>
												<th><?php echo $_['tabel_o/r']; ?></th>
												<th><?php echo $_['tabel_streams']; ?></th>
											</tr>
											</thead>
											<tbody id="tbodyListaStatii">
												
											</tbody>
									</table>
								<div id="aplicaStatii">

								</div>
								</div>
							</div>
							<div class="clearfix"></div>
							<br/>
							<div id="listaverificarerequest">
								<div id="requesttableinfo">
									<table class="table" id="livereqvew">
											<thead>
											<tr>
												<th>Data Request</th>
												<th>Tip Request</th>
												<th>Tip Fetch</th>
												<th>Lista </th>
												<th>Status</th>
											</tr>
											</thead>
											<tbody id="requesturibyemaail">
												
											</tbody>
									</table>

								</div>
							</div>
								
						</div>
					  </div>
					</div>
				  
				  </div>
			</div>
		</div>
		<div id="msgerr"></div>
		
	</div>

	<!--
		
	-->
</body>
	<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
	
	<!--<script src="js/jquery-1.10.2.js"></script>-->
	<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
	<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
	<script src="js/jquery-ui-1.10.4.custom.js"></script>
	<script src="js/timepick.js"></script>
	<!--<script src="js/openlayers/lib/OpenLayers.js" type="text/javascript"></script>-->
	<!--<script src="http://cdnjs.cloudflare.com/ajax/libs/openlayers/2.11/OpenLayers.js"></script>-->
	 <script src="http://openlayers.org/api/OpenLayers.js"></script>

	<script>
	
	var vectors;
	var box;
	var transform;
	function roundLatLon(x) {
		return Math.round(x * 100) / 100;
	};
	map = new OpenLayers.Map('mapEvent' /*,{ controls: [] }*/);
	//map.addControl(new OpenLayers.Control.PanZoomBar());
		
    var gphy = new OpenLayers.Layer.Google(
        "Google Physical",
        {type: google.maps.MapTypeId.TERRAIN, visibility: false}
    );
    map.addLayers([gphy]);
		
	 map.setCenter(new OpenLayers.LonLat(26.00, 44.9).transform(
      epsg4326 =  new OpenLayers.Projection("EPSG:4326"),
       projectTo = map.getProjectionObject()
    ), 4);

    var vectorLayer = new OpenLayers.Layer.Vector("Overlay");

    map.addLayer(vectorLayer);

    var controls = {
      selector: new OpenLayers.Control.SelectFeature(vectorLayer, { onSelect: createPopup, onUnselect: destroyPopup })
    };

    function createPopup(feature) {
      feature.popup = new OpenLayers.Popup.FramedCloud("pop",
          feature.geometry.getBounds().getCenterLonLat(),
          null,
          '<div class="markerContent">'+feature.attributes.description+'</div>',
          null,
          true,
          function() { controls['selector'].unselectAll(); }
      );
      map.addPopup(feature.popup);
    }

    function destroyPopup(feature) {
      feature.popup.destroy();
      feature.popup = null;
    }
    
    map.addControl(controls['selector']);
		 map.addControl(
                new OpenLayers.Control.MousePosition({
                    separator: ' | ',
                    numDigits: 2,
                    emptyString: 'Cordonates',
										displayProjection: "EPSG:4326"
                })
            );
		
    controls['selector'].activate();
		

	
	
var control = new OpenLayers.Control();
var mydiv = [];
OpenLayers.Util.extend(control, {
    draw: function () {
        this.box = new OpenLayers.Handler.Box( control,
            {"done": this.notice},
            {keyMask: OpenLayers.Handler.MOD_SHIFT});
						
        this.box.activate();
    },

    notice: function (bounds) {

			var lb = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.left, bounds.bottom));
			var rt = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.right, bounds.top));

			lb.transform(map.getProjection(), "EPSG:4326");
			rt.transform(map.getProjection(), "EPSG:4326");

			lb.lon = roundLatLon(lb.lon);
			lb.lat = roundLatLon(lb.lat);
			rt.lon = roundLatLon(rt.lon);
			rt.lat = roundLatLon(rt.lat);

			$("#nord").val(rt.lat)
			$("#sud").val(lb.lat)
			$("#vest").val(lb.lon)
			$("#est").val(rt.lon)
				
			if( mydiv.length > 0){
				nr = mydiv.length - 1;
				mydiv[nr][0].remove()
			}else{
			
			}

			var myselect = new OpenLayers.Bounds(lb.lon,lb.lat,rt.lon,rt.lat);
			myselect.transform("EPSG:4326", map.getProjection());
			var boxes = new OpenLayers.Layer.Boxes("lucian");
			var box = new OpenLayers.Marker.Box(myselect, "#008DCF", 3);
			boxes.addMarker(box);
			map.addLayer(boxes);
			map.zoomToExtent(myselect);
			mydiv.push($("#"+box.div.id))
    }
});

map.addControl(control);
	
	
	

	$( "#tabs" ).tabs();
	$("#tabs_resq").tabs({ active: 1 });


	$("#cod").click(function(){
			$("#cauta_statii").attr("onclick","cod()");
	})
	$("#regiune").click(function(){
			$("#cauta_statii").attr("onclick","reg()");
	})
	$("#eveniment").click(function(){
			$("#cauta_statii").attr("onclick","eve()");
	})
	
	
	
	$("#relative").click(function(){
			$("#aplicaFiltru").attr("onclick","relative()");
	})
	$("#absolute").click(function(){
			$("#aplicaFiltru").attr("onclick","absolute()");	
	})

		$('#tabNav a').click(function (e) {
		  e.preventDefault()
		  $(this).tab('show')
			/*
			$("#requesturibyemaail").html('')
			clearInterval(verificareRequest);
			*/
		})
		$('.dataeveniment').datepicker({ 
			dateFormat: 'yy-mm-dd' 
		});
		 $( "#sliderMagnitudine" ).slider({
		  value:3,
		  min: 0.1,
		  max: 10,
		  step: 0.1,
		  slide: function( event, ui ) {
				$( "#magnitudine" ).val(ui.value);
		  }
		});
		$( "#sliderAdancime" ).slider({
			  range: true,
			  min: 0.1,
			  max: 500,
			  values: [ 45, 150 ],
			  slide: function( event, ui ) {
				$( "#adancimeDeLa" ).val(ui.values[ 0 ]);
				$( "#adancimePanaLa" ).val(ui.values[ 1 ]);
			  }
		});
		$( "#sliderstartbefore" ).slider({
		  value:-5,
		  min: -60,
		  max: 0,
		  step: 1,
		  slide: function( event, ui ) {
				$( "#minutebefore" ).val(ui.value);
		  }
		});
		
		$( "#sliderstartend" ).slider({
		  value:5,
		  min: 0,
		  max: 60,
		  step: 1,
		  slide: function( event, ui ) {
				$( "#minuteafter" ).val(ui.value);
		  }
		});
		
		
		
		
		$( "#Event_Distance" ).slider({
			  range: true,
			  min: 1,
			  max: 180,
			  values: [ 1, 180 ],
				 step: 1,
			  slide: function( event, ui ) {
				$( "#fromdist" ).html(ui.values[ 0 ]);
				$( "#fromdist2" ).html(ui.values[ 1 ]);
			  }
		});
		$( "#Event_Azimuth" ).slider({
			  range: true,
			  min: 1,
			  max: 360,
			  values: [ 1, 360 ],
			  slide: function( event, ui ) {
				$( "#fromazmuth" ).html(ui.values[ 0 ]);
				$( "#fromazmuth2" ).html(ui.values[ 1 ]);
			  }
		});
		$(".datetimepick").datetimepicker({
			timeFormat: "HH:mm",
			dateFormat: 'yy-mm-dd'
		});
		
		
		
		$(".steag").click(function(){
			limba = $(this).attr("id");
			$.ajax({
				type:"POST",
				data:{"limba":limba},
				url:"json.php"
			}).done(function(data){
				 location.reload();
			});
		})
		
		//*********** STATII AUTOCOMPLETARE IN TABUL BY COD ************/
		$(document).ready(function() {

			$.ajax({ 
				 type: "GET",
				 dataType: "jsonp",
				 data:{"actiune":"populeazaBycod"},
				 jsonpCallback: "callback",
				 url: "json.php",
				 success: function(data){
					$("#statiiByCod option[value='0']").remove();
						$("#statiiByCod").append(new Option("Selecteaza statie", "0"));
					$.each( data, function(key,val){
							$("#statiiByCod").append(new Option(val.cod_tara + " " + val.cod_statie, val.id_statie));
					})
					
				 }
			 })
			
		});
		//*********** STATII AUTOCOMPLETARE IN TABUL BY COD ************/
		
		

		//*********** GENERARE LISTA SENZORI ************/
		$("#statiiByCod").change(function(){
				id_statie = $( "#statiiByCod option:selected" ).val()
			
				$.ajax({ 
				 type: "GET",
				 dataType: "jsonp",
				 data:{"actiune":"getsenzori","id_statie":id_statie},
				 jsonpCallback: "callback",
				 url: "json.php",
				 success: function(data){
						$(".senzoriSelect option").remove();
						$.each( data, function(key,val){
								$(".senzoriSelect").append(new Option(val, val,1,1));
						})
				 }
				});
		})
		//*********** GENERARE LISTA SENZORI ************//
		
		
		
		//*********** CAUTA EVENIMENT ************//
		$("#cauta_eveniment").click(function(){		
			$("#cauta_statii_eveniment").fadeIn(300);
			de_la_data = $("#de_la_data").val();
			pana_la_data = $("#pana_la_data").val();
			magnitudine = $("#magnitudine").val();
			adancimeDeLa = $("#adancimeDeLa").val();
			adancimePanaLa = $("#adancimePanaLa").val();
			nord = $("#nord").val();
			vest = $("#vest").val();
			est = $("#est").val();
			sud = $("#sud").val();
			
			$.ajax({ 
				 type: "GET",
				 dataType: "jsonp",
				 data:{"actiune":"getdata","de_la_data":de_la_data,"pana_la_data":pana_la_data,"magnitudine":magnitudine,"adancimeDeLa":adancimeDeLa,"adancimePanaLa":adancimePanaLa,"nord":nord,"vest":vest,"est":est,"sud":sud },
				 jsonpCallback: "callback",
				 url: "json.php",
				 success: function(data){
						
						 if(data.succes == 0 ){
							$("#msgerr").dialog({title:"Alerta!"}).html('<p style="text-align:center">'+data.error+'</p>');
						 }else{
							$("#tbodyLista").html("");
							$("#nr_evenimente").html(data.length);
							$("#eveLista").fadeIn(300)
							$.each( data, function( key, val ) {
									var tr;
									tr = $('<tr/>');
									tr.append("<td> <input type='radio' name='eveniment[]' class='evenimenteLista' value='"+ val.id_cutremur +"' id='checkbox_1' /></td>");
									tr.append("<td>" + val.data_eveniment + "</td>");
									tr.append("<td>" + val.mag + "</td>");
									tr.append("<td>" + val.adancime + "</td>");
									tr.append("<td>" + val.lat + "</td>");
									tr.append("<td>" + val.lon + "</td>");
									tr.append("<td>" + val.regiune + "</td>");
									tr.addClass("eveniment_listat");
									tr.attr('id', val.id_cutremur);
									$('#tbodyLista').append(tr);
									
							
									
								//DUPLICATE FOR MULTIPLE POINT MAP SI POPU
								var feature = new OpenLayers.Feature.Vector(
												new OpenLayers.Geometry.Point(val.lon, val.lat).transform(epsg4326, projectTo),
												{description:val.data_eveniment} ,
												{externalGraphic: 'js/openlayers/img/eveniment.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25  }
										);  
								vectorLayer.addFeatures(feature);
								//DUPLICATE FOR MULTIPLE POINT MAP SI POPUp
									
									
							});
							clickTable();
							
										/*
									 $('#evebimenteTB').dataTable( {
											"scrollY":        "200px",
											"scrollCollapse": true,
											"searching": false,
											"paging": false,
											"ordering": false,
											 "info": false
										});
										*/
							
						 }
				 }
			});
			
		})
		//*********** CAUTA EVENIMENT ************//

		
		
		
		//*********** CAUTA STATIE BY COD ************//
			// eroare adauga inca un senzor in plus de gasit
		function cod(){
			id_statie = $("#statiiByCod").val();
			var mySelections = [];
			$('.senzoriSelect option').each(function(i) {
				if (this.selected == true) {
								mySelections.push(this.value);
				}
			});
			
			if(id_statie == 0){
					$("#msgerr").html("");
					$("#msgerr").dialog({"title":"Eroare"}).html("Selecteaza statia pe care vrei sa o adaugi in lista");
			}else{
				$.ajax({ 
					type: "GET",
					dataType: "jsonp",
					data:{"actiune":"getstatiibycod","id_statie":id_statie,"senzorilista":mySelections},
					jsonpCallback: "callback",
					url: "json.php",
						success: function(data){
							$("#boxinfoEveniment").fadeIn(300);
									
							$.each( data, function(key, val){
									var tr;
									tr = $('<tr/>');
									tr.append("<td><input type='checkbox' class='statie_sel' name='statie_sel[]' value='"+ val.id_statie +"' id='checkbox_1' /></td>");
									tr.append("<td>" + val.cod_tara + "</td>");
									tr.append("<td>" + val.cod_statie + "</td>");
									tr.append("<td>" + val.lat + "</td>");
									tr.append("<td>" + val.lng + "</td>");
									tr.append("<td>" + val.altitudine + "</td>");
									tr.append("<td style='width:250px;' id='canale"+val.id_statie+"'>"+mySelections+"</td>");
									tr.addClass("statie_lista");
									tr.attr('id', val.id_statie);
									$("#tbodyListaStatii").append(tr);
									
									
								//DUPLICATE FOR MULTIPLE POINT MAP SI POPU
								var feature = new OpenLayers.Feature.Vector(
												new OpenLayers.Geometry.Point(val.lng, val.lat).transform(epsg4326, projectTo),
												{description:val.cod_statie} ,
												{externalGraphic: 'js/openlayers/img/statie.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25  }
										);  
								vectorLayer.addFeatures(feature);
								//DUPLICATE FOR MULTIPLE POINT MAP SI POPUp
									
									
									
									
								})
							
						}
					
					});
				}

			
		}
		//*********** CAUTA STATIE BY COD ************//
		
		
		
		
		//*********** CAUTA STATIE BY REGIUNE ************//
		function reg(){
			
					alert("REG")
			
		}
		//*********** CAUTA STATIE BY REGIUNE ************//
	
	
	
	
		//*********** CAUTA STATIE BY EVENIMENT ************//
		function eve(){
					$("#msgerr").html("");
					$("#msgerr").dialog().html("Statiile au fost adaugate, determina requestul pe care l doresti!");
					$('.nav-tabs > .active').next('li').find('a').trigger('click');
			
		}
		//*********** CAUTA STATIE BY EVENIMENT ************//
		
		
		
		
		
		function clickTable(){
			var dataSelect = { 'eveniment[]' : []};
			
			$("#cauta_statii_eveniment").click(function(){

				$('.evenimenteLista:checked').each(function() {
					dataSelect['eveniment[]'].push($(this).val());
				});
				dataSelect['actiune'] = 'getstatiidupaeveniment';
					$("#statiidupaeveniment").html("");
				$.ajax({ 
				type: "GET",
				dataType: "jsonp",
				data:dataSelect,
				jsonpCallback: "callback",
				url: "json.php",
					success: function(data){
						$("#msgerr").html("");
						$("#msgerr").dialog().html("S au adaugat statiile atribuite evenimentelor selectate.<br/>  Click pe tabul <b>Statii</b> din meniu, si apoi pe subtabul <b>Evenimente</b> ");
						$.each( data, function(key, val){
								var tr;
								tr = $('<tr/>');
								tr.append("<td><input type='checkbox' class='statie_sel statiidineveniment' name='statie_sel[]' value='"+ val.id_statie_eveniment +"' id='checkbox_22' /></td>");
									tr.append("<td>" + val.id_eveniment + "</td>");
								tr.append("<td>" + val.tara + "</td>");
								tr.append("<td>" + val.statie + "</td>");
								tr.addClass("statie_lista");
								tr.attr('id', val.id_statie);
								
								$("#statiidupaeveniment").append(tr);
							})
					}
				
				});
	
				
			})

		}
		
		
		
		
		
		//*********** CAUTA STATIE BY EVENIMENT RELATIVE ************//
		
			function relative(){
				var selectiiStatiis = [];
				var canale = [];
				$('.statie_sel:checked').each(function(i) {
					if (this.checked == true) {
							selectiiStatiis.push(this.value);
							canale.push($("#canale"+this.value).text());
					}
				});
				
				var evenimente = [];
				$('.evenimenteLista:checked').each(function(i) {
					if (this.checked == true) {
							evenimente.push(this.value);
					}
				});
				
			
				var allstation = $("input[name='allstation']:checked").val();
				var minutebefore = $("#minutebefore").val();
				var minuteafter = $("#minuteafter").val();
				var tipResquest = $("input[name='tipResquest']:checked").val();
				var tipfetch = $("input[name='tipfetch']:checked").val();
				var email = $("input[name='email']").val();

			
				if(evenimente.length == 0){
					return errorReq_relative("eveniment_err");
				}

				if(allstation == "nu"){
					if(selectiiStatiis.length == 0){
						return errorReq_relative("statii");
					}
				}
				
				if(minutebefore.length == 0){
					return errorReq_relative("datastart");
				}
				
				if(minuteafter.length == 0){
					return errorReq_relative("dataend");
				}
				
				if(email.length == 0){
					return errorReq_relative("email");
				}
				$("#infoBlack").html("Requestul tau a fost trimis vei primi un email pentu a putea descarca forma de unda ceruta.<br/>")
				$("#black").fadeIn(300);
				
				
			
				$.ajax({ 
					type: "GET",
					data:{"actiune":"resqueststatii_relative","evenimente":evenimente,"id_statie":selectiiStatiis,"canale":canale,"allstation":allstation,"minutebefore":minutebefore,"minuteafter":minuteafter,"tipresq":tipResquest,"tipfetch":tipfetch,"email":email},
					url: "json.php"
				})
					
			}
			
			function errorReq_relative(tiperoare){
			
				switch(tiperoare){
					case "eveniment_err":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("Selecteaza cel putin un eveniment din lista.");
					break;
					case "statii":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("Bifeaza cel putin o statie din lista.");
					break;
					case "datastart":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("seteaza minutele inainte de eveniment");
					break;
					case "dataend":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("Seteaza minuele dupa eveniment");
					break;
					case "email":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("Foloseste un email valid pentru a iti fi trimis linkul pentru a descarca miniseed");
					break;
					
					
					
				}
			}
			
		//*********** CAUTA STATIE BY EVENIMENT RELATIVE ************//
		
		//*********** CAUTA STATIE BY EVENIMENT ABSOLUTE ************//

			function absolute(){
		
					$.ajaxSetup({
            async: true
					});
				
				var selectiiStatiis = [];
				var canale = [];
				$('.statie_sel:checked').each(function(i) {
					if (this.checked == true) {
							selectiiStatiis.push(this.value);
							canale.push($("#canale"+this.value).text());
					}
				});
				
			
				var allstation = $("input[name='allstation']:checked").val();
				var startdate = $("#startdatetrim").val();
				var enddate = $("#enddatetrim").val();
				var tipResquest = $("input[name='tipResquest']:checked").val();
				var tipfetch = $("input[name='tipfetch']:checked").val();
				var email = $("input[name='email']").val();

				
				if(allstation == "nu"){
					if(selectiiStatiis.length == 0){
						return errorReq("statii");
					}
				}
				
				if(startdate.length == 0){
					return errorReq("datastart");
				}
				
				if(enddate.length == 0){
					return errorReq("dataend");
				}
				
				if(email.length == 0){
					return errorReq("email");
				}
				$("#infoBlack").html("Requestul tau a fost trimis vei primi un email pentu a putea descarca forma de unda ceruta.<br/>")
				$("#black").fadeIn(300);
				
				
				
				$.get("json.php", {"actiune":"resqueststatii_absolute","id_statie":selectiiStatiis,"canale":canale,"allstation":allstation,"startdate":startdate,"enddate":enddate,"tipresq":tipResquest,"tipfetch":tipfetch,"email":email}, function(data) { 
				
				
				/*
					if (data && data != "") {
						$("#news_feed").prepend($(data).fadeIn('slow'));
					}
				*/
				});
			
			/*
				$.ajax({ 
					type: "GET",
					async: true,
					data:{"actiune":"resqueststatii","id_statie":selectiiStatiis,"canale":canale,"allstation":allstation,"startdate":startdate,"enddate":enddate,"tipresq":tipResquest,"tipfetch":tipfetch,"email":email},
					url: "json.php"
				})
				*/
					
				
				/*
				$.ajax({ 
					type: "GET",
					dataType: "json",					
					data:{"actiune":"resqueststatii","id_statie":selectiiStatiis,"canale":canale,"allstation":allstation,"startdate":startdate,"enddate":enddate,"tipresq":tipResquest,"tipfetch":tipfetch,"email":email},
					url: "json.php",
					}).done(function(data){
						$("#black").fadeOut(300);
						if(data.succes == 0){
								$("#msgerr").html("");
								$("#msgerr").dialog({"title":"error"}).html(data.error);
							}else{
								$("#msgerr").html("");
								$("#msgerr").dialog({"title":"Succes"}).html(data.error);
							}
						
					})
					*/
				
				
				/*
				$.ajax({ 
					type: "GET",
					dataType: "jsonp",					
					data:{"actiune":"resqueststatii","id_statie":selectiiStatiis,"canale":canale,"allstation":allstation,"startdate":startdate,"enddate":enddate,"tipresq":tipResquest,"tipfetch":tipfetch,"email":email},
					jsonpCallback: "callback",
					url: "json.php",
					success: function(data){
						alert(data)
									if(data.succes == 0){
										$("#msgerr").html("");
										$("#msgerr").dialog({"title":"error"}).html(data.error);
									}else{
										$("#msgerr").html("");
										$("#msgerr").dialog({"title":"Succes"}).html(data.error);
									}
						}
					});
				*/
					
			


			}
			
			function errorReq(tiperoare){
			
				switch(tiperoare){
					case "statii":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("Bifeaza cel putin o statie din lista.");
					break;
					case "datastart":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("Seteaza data de inceput");
					break;
					case "dataend":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("Seteaza data de sfarsit");
					break;
					case "email":
						$("#msgerr").html("");
						$("#msgerr").dialog({"title":"Eroare"}).html("Foloseste un email valid pentru a iti fi trimis linkul pentru a descarca miniseed");
					break;
					
					
				}
			
			}
		
		
		//*********** CAUTA STATIE BY EVENIMENT ABSOLUTE ************//
		
		
		/*******************VERIFICARE REQUEST ************/
		
		
		$("#verifica_request").click(function(){
			email = $("#email_vf").val();
			$("#infoBlack").html("Va rugam asteptati. Se primesc informatii.<br/>");
			$("#black").fadeIn(300);
		 verificareRequest =	setInterval(function(){
				$("#black").fadeOut(300);
				$.ajax({ 
						type: "GET",
						dataType: "jsonp",
						data:{"actiune":"verificarequest","email":email},
						jsonpCallback: "callback",
						url: "json.php",
							success: function(data){
								
								if(data.succes == 0){
									$("#msgerr").html("");
									$("#msgerr").dialog({"title":"Eroare"}).html("Nu exista nici un request pe aceasta adresa de email");
								}else{
									
									
										$("#requesttableinfo").fadeIn(300);
										$("#requesturibyemaail").html('')
										$.each( data, function(key, val){
												var tr;
												tr = $('<tr/>');
												tr.append("<td>" + val.data_res + "</td>");
												tr.append("<td>" + val.tip_res + "</td>");
												tr.append("<td>" + val.tip_fetch + "</td>");
												tr.append("<td>" + val.list_res + "</td>");
												tr.append("<td>" + val.status + "</td>");
												tr.addClass(val.status);
												$("#requesturibyemaail").append(tr);
														
										})
	
									
								}
								
							}
						
						});
			},1000);
					

			
		})
		
		
		/*******************VERIFICARE REQUEST ************/
		
		/*******************CECK ALL******************/
		

		
		
		$(document).ready(function() {
				$('#select_all').click(function(event) {  
						if(this.checked) { 
								$('.statiidineveniment').each(function() {
										this.checked = true;                 
								});
						}else{
								$('.statiidineveniment').each(function() { 
										this.checked = false;             
								});         
						}
				});
				
		});
		
		
		/******************checkll ************************/
		
		
		
	</script>
</html>	
